package com.aqie.easy.bitOperation;

/**
 * @Function: 762. 二进制表示中质数个计算置位
 * @Author: aqie
 * @Date: 2019/6/30 8:54
 */
public class CountPrimeSetBits {
    public int countPrimeSetBits(int L, int R) {
        int ans = 0;
        for (int i = L; i <= R; i++){
            int num = Integer.bitCount(i);
            if (isPrime(num)){
                System.out.println(i + " " + num);
                ans++;
            }
        }
        return ans;
    }

    // 判断一个数是否是质数
    private boolean isPrime(int num) {
        if (num <= 1) return false;
        for(int i = 2; i<num; i++){
            if (num % i == 0){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int L = 9;
        // 获取整数的二进制位个数
        int i = Integer.bitCount(9);

        CountPrimeSetBits cpsb = new CountPrimeSetBits();
        int res = cpsb.countPrimeSetBits(244, 269);
        // System.out.println(res);

    }


}
